package sdiff.tests;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * Maps location string to multiple location results.
 * 
 * For example:
 * 
 * <LOCATION ID="L_5" ORIG="5" NEW="10">
      <METHOD ID="sdiff-token" LINE="10"/>
      <METHOD ID="sdiff-normal" LINE="10"/>
 * 
 * @author jspacco
 *
 */
public class ReissLocationMap
{
    private Map<String, Set<String>> map=new TreeMap<String,Set<String>>();
    
    public void put(String key, String value) {
        addKey(key);
        map.get(key).add(value);
    }
    
    public void addKey(String key) {
        if (!map.containsKey(key)) {
            map.put(key, new TreeSet<String>());
        }
    }
    
    public String toXMLString() {
        StringBuffer buf=new StringBuffer();
        for (Map.Entry<String,Set<String>> entry : map.entrySet()) {
            buf.append(entry.getKey()+"\n");
            for (String methodLine : entry.getValue()) {
                buf.append("  "+methodLine+"\n");
            }
            buf.append("</LOCATION>\n");
        }
        return buf.toString();
    }
}
